package com.goods.controller.business;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.goods.business.service.ProductService;
import com.goods.business.service.ProductStockService;
import com.goods.common.model.business.Product;
import com.goods.common.model.business.ProductStock;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "业务管理-物资资料")
@RestController
@RequestMapping("/business/product")
public class ProductController {
    @Autowired
    private ProductService productService;
   @Autowired
   private ProductStockService productStockService;


    @ApiOperation("分页查询物资资料")
    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize", defaultValue = "7") Integer pageSize,
                                        ProductVO productVO){
        PageVO<ProductVO> pageVOList = productService.findProductList(pageNum,pageSize,productVO);
        return ResponseBean.success(pageVOList);
    }
    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        return ResponseBean.success(productService.add(productVO));
    }
    @ApiOperation("修改回显")
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        return ResponseBean.success(productService.edit(id));
    }
    @ApiOperation("修改确认")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductVO productVO){
        return ResponseBean.success(productService.update(id,productVO));
    }
    @ApiOperation("移入回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        return ResponseBean.success(productService.remove(id));
    }
    @ApiOperation("回收站撤销")
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        return ResponseBean.success(productService.back(id));
    }
    @ApiOperation("回收站删除")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        return ResponseBean.success(productService.delete(id));
    }
    @ApiOperation("审批通过")
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        return ResponseBean.success(productService.publish(id));
    }
    @ApiOperation("查询入库时的分类")
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "7") Integer pageSize,
                                     ProductVO productVO){
        PageVO<ProductVO> pageVOList = productService.findProductList(pageNum,pageSize,productVO);
        return ResponseBean.success(pageVOList);
    }
    @ApiOperation("查询物资库存")
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "7") Integer pageSize,
                                     ProductVO productVO){
        PageVO<ProductVO> pageVOList = productService.findProductList(pageNum,pageSize,productVO);
        return ResponseBean.success(pageVOList);
    }
    @ApiOperation("查询物资库存")
    @GetMapping("/findProductStocks")
    public ResponseBean<PageVO<ProductStockVO>> findProductStocks(@RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize, @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, String categorys, String name) {
        PageVO<ProductStockVO> p = productService.findProductStocks(pageSize, pageNum, categorys, name);
        return ResponseBean.success(p);
    }



}
